// pages/UserStatistics/Userindex/UserIndex.js
const controllers = require('../../controllers/controllerIndex.js').controller;
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // status:-1,
    time:false,	 
    pay: false,
    activeIndex:0,
    tabs: [
      {
        name: "全部",
        // type: 0,
        vip:null,//是否vip
        // isActive: true
      },
      {
        name: "普通用户",
        // type: 1,
        vip: 0,//是否vip
        // isActive: false
      },
      {
        name: "会员",
        // type: 1,
        vip: 2,//是否vip
        // isActive: false
      },
      {
        name: "VIP会员",
        // type: 2,
        vip: 1,//是否vip
        // isActive: false
      },
      {
        name: "股东",
        // type: 1,
        vip: 3,//是否vip
        // isActive: false
      },
      {
        name: "代理商",
        // type: 1,
        vip: 4,//是否vip
        // isActive: false
      }
    ],
    typeList:["手机号","昵称"],
    typeName:"手机号",
    index:1,
    inputText:'',
    icon1:"https://xinlingshoushangquan.oss-cn-shenzhen.aliyuncs.com/account/20210414/831918901884354560.png",
    icon2:"https://xinlingshoushangquan.oss-cn-shenzhen.aliyuncs.com/account/20210414/831919079068532736.png",
    store:"",
    pageNumber:1,
    lastPage:false
  },

  //跳转提现文案设置
  // toSetBeanDesc(){
  //   wx.navigateTo({
  //     url: '/pages/userStatistics/Userindex/setBeanDesc',
  //   })
  // },

  seletBalance(){
    let pay=this.data.pay;
    this.setData({
      pay:pay?false:true,
      isTime:false
    })
    this.getUserList()
  },
  seletTime(){
    let time=this.data.time;
    this.setData({
      time:time?false:true,
      isTime:true
    })
    this.getUserList()
  },

  //切换名称和号码搜索
  bindTypeChange(e){
    let index=e.detail.value;
    if(index==0){
      this.setData({
        index:1,
        typeName:"手机号"
      })
    }else{
      this.setData({
        index:0,
        typeName:"昵称"
      })
    }
  },

  //获取输入数据
  getSearchText(e){
    this.setData({
      inputText:e.detail.value
    })
    this.getUserList()
  },

  getUserList(){
    let that =this
    let time =this.data.time
    let pay =this.data.pay
    let isTime=this.data.isTime
    let params={
      sessionId: wx.getStorageSync('token'),
      shopId:wx.getStorageSync('shopId')
    }
    this.setData({
      pageNumber:1
    })
    params.pageNumber=this.data.pageNumber
    if(this.data.index==0){
      params.nick=this.data.inputText
    }else{
      params.mobile=this.data.inputText
    }
    // if(isTime){
    //   params.time=time?"DESC":"ASC" 
    // }else{
    //   params.pay=pay?"DESC":"ASC"
    // }

    params.time="ASC"

    let item = this.data.tabs[this.data.activeIndex];
    if(null!=item.vip){
      params.vip = item.vip;
    }
    
    controllers.accountListPage(
      params
    ).then(res =>{

      // res.data.list.forEach(item=>{
      //   item.accountMobile=item.accountMobile.slice(0,3)+"****"+item.accountMobile.slice(7)
      // })

      that.setData({
        userList:res.data.list,
        lastPage:res.data.lastPage
      })
    })
  },

  getMore(){
    if(this.data.lastPage==false){
      let that =this
      let time =this.data.time
      let pay =this.data.pay
      let isTime=this.data.isTime
      let params={
        sessionId: wx.getStorageSync('token'),
        shopId:wx.getStorageSync('shopId')
      }
      params.pageNumber=this.data.pageNumber+1
      this.setData({
        pageNumber:params.pageNumber
      })
      if(this.data.index==0){
        params.nick=this.data.inputText
      }else{
        params.mobile=this.data.inputText
      }
      // if(isTime){
      //   params.time=time?"DESC":"ASC" 
      // }else{
      //   params.pay=pay?"DESC":"ASC"
      // }

      params.time="ASC"

      let item = this.data.tabs[this.data.activeIndex];
      if(null!=item.vip){
        params.vip = item.vip;
      }
      
      controllers.accountListPage(
        params
      ).then(res =>{
        let list=this.data.userList
        let list2=res.data.list
        let list3=list.concat(list2)
        that.setData({
          userList:list3,
          lastPage:res.data.lastPage
        })
      })
    }
  },

  clikcTabs(e) {
    const   index   = e.currentTarget.dataset.index
    
    this.setData({
      activeIndex:index
    });
    // let tabs = this.data.tabs
    
    // tabs.forEach((v, i) => i === index ? v.isActive = true : v.isActive = false);
    // this.setData({
    //   tabs,
    //   status:index-1
    // })
      this.getUserList()
  },

  onLoad: function (options) {
    if(options.storeInfo){
      this.setData({
        storeInfo:JSON.parse(options.storeInfo)
      })
    }
    this.getUserList();
  },
  clikcDetails(res) {
   
    wx.navigateTo({
      url: '../UserDeatils/UserDeatils?id='+ res.currentTarget.dataset.id+"&accountId="+res.currentTarget.dataset.accountid
    })
  },
  onShow: function () {

  },

  onReachBottom: function () {
    this.getMore()
  },

  
})